<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .text1 {
            width: 200px;
            height: 20px;
            text-align: center;
            border: 1px solid #000;
        }

        .text2 {
            width: 200px;
            height: 20px;
            text-align: center;
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <div class="text1">
    </div>
    <div class="text2"></div>
    时间戳：

    <span></span>
    <script>
        const text1 = document.querySelector('.text1')
        const text2 = document.querySelector('.text2')
        const span = document.querySelector('span')

        const date = new Date()
        function getTime() {
            const date = new Date()
            year = date.getFullYear() > 9 ? date.getFullYear() : '0' + date.getFullYear()
            month = date.getMonth() > 9 ? date.getMonth() : '0' + date.getMonth()
            day = date.getDate() > 9 ? date.getDate() : '0' + date.getDate()
            hour = date.getHours() > 9 ? date.getHours() : '0' + date.getHours()
            minute = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes()
            second = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds()
            return `${year}年${+month + 1}月${day}日 ${hour}:${minute}:${second}`
        }
        text1.innerHTML = getTime()
        setInterval(function () {
            text1.innerHTML = getTime()
        }, 1000);

        // const date = new Date()
        text2.innerHTML = date.toLocaleString()
        setInterval(function () {
            const date = new Date()
            text2.innerHTML = date.toLocaleString()
        }, 1000);
        const time = +new Date()
        // document.write(time)
        span.innerHTML = time
        const n = (+new Date('2025-11-21')) - (+new Date())
        document.write('<br>' + '将来的时间戳：' + (+ new Date('2025-11-21')) + '<br>')
        document.write('现在的时间戳：' + (+ new Date()) + '<br>')
        document.write('差值：' + n)
    </script>
</body>

</html>